import { defHttp } from '@/utils/http/axios'
import type { IEditRoleItem, IRoleItem } from './model'

enum API {
  ROLE_LIST = '/role/list',
  UPDATE_ROLE = '/role/'
}

const DEFAULT_OPTS = {
  isTransformResponse: false
}


/** 获取角色列表 */
export const getRoleList = (): Promise<IRoleItem[]> => {
  return defHttp.get({
    url: API.ROLE_LIST,
  }, DEFAULT_OPTS)
}

/** 新增角色 */
export const addRole = (data: IEditRoleItem) => {
  return defHttp.post({
    url: API.UPDATE_ROLE,
    data
  }, DEFAULT_OPTS)
}

/** 删除角色 */
export const delRole = (id: string) => {
  return defHttp.delete({
    url: API.UPDATE_ROLE + id
  }, DEFAULT_OPTS)
}

/** 编辑角色 */
export const editRole = (data: IEditRoleItem) => {
  return defHttp.put({
    url: API.UPDATE_ROLE,
    data
  }, DEFAULT_OPTS)
}